package edu.zut.cs.network.Experiment4;

import javax.swing.JOptionPane;

public class SumDigits {
    public static int sumDigits(long n){
        int num = 0;
        while(n > 0) {
            int temp = (int)(n % 10);
            num = num + temp;
            n = n / 10;
        }
        return num;
    }
    public static void main(String[] args) {
//        计算一个整数中的各个数字的和
        String str = JOptionPane.showInputDialog("请输入一个整数：");
        long lo = Long.parseLong(str);
        int number = sumDigits(lo);
        JOptionPane.showMessageDialog(null,
                "该整数各个数字之和为："+number,
                "运行结果：",JOptionPane.INFORMATION_MESSAGE);
    }
}
